#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <cstdlib>
#include <map>
#include <bitset>
#include <unordered_map>
#include <ctime>
#include <vector>
#include <queue>
#include <list>

#define R register
#define L long
#define LL long long
#define I inline
#define U unsigned
using namespace std;

I LL read()
{
    R LL   x;
    R bool f;
    R char c;
    for(f=0;(c=getchar())<'0'||c>'9';f=c=='-');
    for(x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}

typedef struct node
{
    struct node*l,*r;
    int        data;
}node;
#define MAXN 33
int hou[MAXN],zhong[MAXN];

node*newNode()
{
    node*tmp=(node*)malloc(sizeof(node));
    tmp->l=tmp->r=NULL;
    tmp->data=0;
    return tmp;
}

node*build(int n,int hou[],int zhong[])
{
    if(n<=0)
        return NULL;
    node*p=newNode();
    p->data=hou[n-1];
    int i=0;
    for(;i<n&&(zhong[i]!=p->data);++i);
    p->l=build(i,hou,zhong);
    p->r=build(n-i-1,hou+i,zhong+i+1);
    return p;
}
void visit(node * rt)
{
    if(rt)
    {
        printf(" %d",rt->data);
        visit(rt->l);
        visit(rt->r);
    }
}

int main()
{
    freopen("7-2.in","r",stdin);
//  freopen("7-2.out","w",stdout);
    int n=read();
    for(int i=0;i<n;hou[i]=read(),++i);
    for(int i=0;i<n;zhong[i]=read(),++i);
    printf("Preorder:");
    visit(build(n,hou,zhong));
    
    
    fclose(stdin);
    fclose(stdout);
    return 0;
}